package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.CollectMapper;
import com.lanyan.system.domain.Collect;
import com.lanyan.system.domain.vo.CollectVo;
import com.lanyan.system.service.ICollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 收藏Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class CollectServiceImpl  extends ServiceImpl<CollectMapper,Collect> implements ICollectService

{
    @Autowired
    private CollectMapper collectMapper;

    /**
     * 查询收藏
     *
     * @param collectId 收藏主键
     * @return 收藏
     */
    @Override
    public Collect selectCollectByCollectId(Long collectId)
    {
        return this.getById(collectId);
    }

    /**
     * 查询收藏Vo列表
     *
     * @param collect 收藏
     * @return 收藏
     */
    @Override
    public List<CollectVo> selectCollectVoList(Collect collect)
    {
        return selectCollectList(collect)
                .stream()
                .map(x -> (CollectVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询收藏列表
     *
     * @param collect 收藏
     * @return 收藏
     */
    @Override
    public List<Collect> selectCollectList(Collect collect)
    {
        LambdaQueryChainWrapper<Collect> wrapper = this.lambdaQuery().eq(Collect::getDelFlag,"0");
        if (collect.getAccountId() != null) {
            wrapper.eq(Collect::getAccountId, collect.getAccountId());
        }
        if (collect.getProductId() != null) {
            wrapper.eq(Collect::getProductId, collect.getProductId());
        }
        return wrapper.list();
    }

        /**
         * 新增收藏
         *
         * @param collect 收藏
         * @return 结果
         */
    @Override
        public boolean insertCollect(Collect collect)
        {
                    collect.setCreateTime(DateUtils.getNowDate());
                return this.save(collect);
        }

        /**
         * 修改收藏
         *
         * @param collect 收藏
         * @return 结果
         */
    @Override
        public boolean updateCollect(Collect collect)
        {
                    collect.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(collect);
        }

        /**
         * 批量删除收藏
         *
         * @param collectIds 需要删除的收藏主键
         * @return 结果
         */
    @Override
        public boolean deleteCollectByCollectIds(Long[] collectIds)
        {
            return this.lambdaUpdate().set(Collect::getDelFlag,"1").in(Collect::getCollectId,collectIds).update();
        }

        /**
         * 删除收藏信息
         *
         * @param collectId 收藏主键
         * @return 结果
         */
    @Override
        public boolean deleteCollectByCollectId(Long collectId)
        {
            return this.lambdaUpdate().set(Collect::getDelFlag,"1").eq(Collect::getCollectId,collectId).update();
        }
    }
